package com.fenghongzhang.day005;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;

import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recycle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        recycle = (RecyclerView) findViewById(R.id.recycle);

        List<Video> list =  new ArrayList<>();
        for (int i = 0; i < TestVideoUrl.videoUrls.length; i++) {
            list.add(new Video());
        }
        MyAdapter myAdapter = new MyAdapter(R.layout.rv_layout,list);
        recycle.setAdapter(myAdapter);

        recycle.setLayoutManager(new MyLieanManager(this));

        //翻页以后自动开始播放
        recycle.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                switch (newState){
                    case RecyclerView.SCROLL_STATE_IDLE:
                        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
                        StandardGSYVideoPlayer gsyVideoPlayer= layoutManager.getChildAt(0).findViewById(R.id.gsy);
                        gsyVideoPlayer.startPlayLogic();
                        break;
                }
            }
        });


    }

}
